package com.web.portal.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.web.portal.mapper.ArticleMapper;
import com.web.portal.pojo.Article;
import com.web.portal.pojo.LabelArticle;
import com.web.portal.services.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article>
        implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public Article selectByArticleCode(String articleCode) {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("article_code", articleCode);
        return articleMapper.selectOne(queryWrapper);
    }

    /**
     * 阅读量+1
     *
     * @param article
     */
    @Async
    @Override
    public void addReadership(Article article) {
        article.setViewCount(article.getViewCount() + 1);
        articleMapper.updateById(article);
    }
}
